package cn.tworice.client.service;

import cn.tworice.admin.service.InductsListenerService;
import cn.tworice.client.dao.PortDao;
import cn.tworice.common.entity.code.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PortService implements InductsListenerService<Port> {
    @Autowired
    private PortDao dao;

    public List<Port> getList(Integer page, Integer pageSize, Port entity) {
        return dao.queryList(page * pageSize, pageSize, entity);
    }

    public int getTotal(Port entity) {
        return dao.queryTotal(entity);
    }

    public void set(Port entity) {
        if (entity.getId() == null) {
            Port port=dao.queryInfoByPort(entity.getPort());
            if(port==null){
                entity.setDate(System.currentTimeMillis());
                dao.insert(entity);
            }

        } else {
            dao.update(entity);
        }
    }

    public void del(Integer[] ids) {
        dao.del(ids);
    }

    @Override
    public int save(List<Port> list) {
        list.forEach(item -> {
            item.setDate(System.currentTimeMillis());
        });
        return dao.insertList(list);
    }
}